/// @tags: Tarjan Graph
#include <cstdio>
#include <functional>
#include <iostream>
#include <numeric>
#include <stack>

using std::cin, std::cout, std::endl;

namespace BlueQuantum {

constexpr int maxn = 5e5 + 2, maxe = 1e6 + 2;

int ecnt;
int heads[maxn];

struct Edge {
  int v, nxt;
} e[maxe];

inline void add(int u, int v) {
  e[++ecnt].v = v, e[ecnt].nxt = heads[u], heads[u] = ecnt;
}

int dcnt, ccnt;
int col[maxn], tot[maxn], sum[maxn];
int dfn[maxn], low[maxn], ins[maxn];
std::stack<int> stk;

void tarjan(int x) {
  dfn[x] = low[x] = ++dcnt;
  stk.push(x);
  ins[x] = true;

  for (int i = heads[x]; i; i = e[i].nxt) {
    int v = e[i].v;
    if (!dfn[v]) {
      tarjan(v);
      low[x] = std::min(low[x], low[v]);
    } else if (ins[v]) {
      low[x] = std::min(low[x], dfn[v]);
    }
  }
  if (dfn[x] == low[x]) {
    ccnt++;
    int y;
    do {
      y = stk.top();
      ins[y] = false;
      col[y] = ccnt;
      tot[ccnt]++;
      stk.pop();
    } while (y != x);
  }
}

int tmp[maxn];

int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= m; ++i) {
    for (int j = 1; j <= n; ++j) {
      cin >> tmp[j];
    }
    for (int j = 2; j <= n; ++j) {
      add(tmp[j - 1], tmp[j]);
    }
  }
  for (int i = 1; i <= n; ++i) {
    if (!dfn[i]) tarjan(i);
  }
  for (int i = 1; i <= ccnt; ++i) {
    tot[i] += tot[i - 1];
  }
  for (int i = 1; i <= n; ++i) {
    cout << tot[col[i]] - 1 << " ";
  }
  return 0;
}

}  // namespace BlueQuantum

int main() {
#ifndef ONLINE_JUDGE
#ifdef LOCAL
  freopen("/tmp/CodeTmp/testdata.in", "r", stdin);
  freopen("/tmp/CodeTmp/testdata.out", "w", stdout);
#else
  freopen("K. My University Is Better Than Yours.in", "r", stdin);
  freopen("K. My University Is Better Than Yours.out", "w", stdout);
#endif
#endif

  std::ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  return BlueQuantum::main();
}
